package org.example.chapter.dao;

import org.apache.ibatis.annotations.*;
import org.example.chapter.emity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {

    @Autowired
     JdbcTemplate jdbcTemplate;

    @Results(id = "1", value = {
            @Result(id = true, property = "name", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "id", column = "id"),
    })
    @Select("select * from user where username = #{username} and password = #{password}")
    User getUserByName(@Param("userName") String name, String password) {
        return null;
    }

    @Insert("Insert into user(username,password,sex) value (#{username},#{password},#{sex})")
    int creatUser(User user) {
        return 0;
    }
    @Delete("delete from user where username = #{username} and password = #{password}")
    
    @Update("update user")


    public  User getUserByName(String username){
        String sql="select * from user where username=?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class),username);

    }
}
